package com.squirrels.server.message;

import com.squirrels.server.message.protobuf.Message;
import dev.morphia.annotations.*;
import lombok.Data;
import org.bson.types.ObjectId;

import java.time.LocalDateTime;

/**
 * 创建者: FlyingSquirrels
 * 创建时间: 2024/7/30 9:44
 * 描述: 登录实体对象
 */
@Data
@Entity("login")
@Indexes(
        @Index(fields = @Field("username"))
)
public class Login {
    @Id
    private String id;

    private String username;

    private String password;

    private LocalDateTime time;

    public static Login fromEntity(Message.Entity entity){
        Message.User user = entity.getUser();
        Login login = new Login();
        login.username = user.getUsername();
        login.password = user.getPassword();
        login.time = LocalDateTime.now();
        return login;
    }

    // 账号不能为空
    public static boolean accountIsNotNull(Login login){
        if (null == login){
            return false;
        }
        if(null != login.getPassword() &&
                null != login.getUsername() &&
                "" != login.getPassword() &&
                "" != login.getUsername()){
            return true;
        }
        return false;
    }
}
